/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#include "SkyManager.h"

namespace PQClient
{
	enum SkyBoxes
	{
		Sky_Box_ClubTropicana,
		Sky_Box_EarlyMorning,
		Sky_Box_Clouds,

		Sky_Box_Num,
	};

	Ogre::String __skyBoxes[Sky_Box_Num] = 
			   {"Sky/ClubTropicana",
				"Sky/EarlyMorning",
				"Sky/Clouds"};

	Ogre::Vector3 __sunPosition[Sky_Box_Num] = 
			   {Ogre::Vector3(0,10000,0),
				Ogre::Vector3(0,10000,90000),
				Ogre::Vector3(0,10000,0)};

	Ogre::Vector3 __sunColor[Sky_Box_Num] = 
			   {Ogre::Vector3(1, 0.9, 0.6),
				Ogre::Vector3(1,0.6,0.4),
				Ogre::Vector3(0.45,0.45,0.45)};

	int __currentSkyBox = 0;

	SkyManager::SkyManager(PQEngine::SceneObject* sceneObject)
		: _sceneObject(sceneObject)
	{
		_sceneMgr=_sceneObject->getSceneManager();
		// Set default ambient light
		_sun = _sceneMgr->createLight("SunLight");

		updateSky();
	}

	void SkyManager::updateSky()
	{
		// Create the SkyBox
		_sceneMgr->setAmbientLight(Ogre::ColourValue(__sunColor[__currentSkyBox].x,__sunColor[__currentSkyBox].y,__sunColor[__currentSkyBox].z));

		_sceneMgr->setSkyBox(true, __skyBoxes[__currentSkyBox], 99999*3, true);
		
		// Create Sun light
		_sun->setPosition(__sunPosition[__currentSkyBox]);
		_sun->setDiffuseColour(1, 1, 1);
		_sun->setSpecularColour(__sunColor[__currentSkyBox].x,__sunColor[__currentSkyBox].y,__sunColor[__currentSkyBox].z);
	}


	void SkyManager::update(float deltaT)
	{
	}

	void SkyManager::setSky(int index)
	{
		__currentSkyBox=index;
		
		updateSky();
	}

	int SkyManager::getSky()
	{
		return __currentSkyBox;
	}

}


